import httpx
from volcenginesdkarkruntime import Ark


class ZhiDaoImgLocationReader:
    client: Ark

    def __init__(self):
        # proxies = {
        #     'http': "http://bjproxy2.cicc.group:8080",  # 代理1
        #     'https': "http://bjproxy2.cicc.group:8080",  # 代理2
        # }
        # 从环境变量中读取您的方舟API Key
        self.client = Ark(
            api_key="075861dc-d8ba-42a1-9683-5ec054173a78",
            base_url="https://ark.cn-beijing.volces.com/api/v3",
            http_client=httpx.Client(proxy="http://bjproxy2.cicc.group:8080")
        )

    def read(self, url: str, question: str):
        # 创建一个对话请求
        completion = self.client.chat.completions.create(
            # 按需替换 Model ID
            model="doubao-seed-1-6-251015",
            messages=[
                {
                    # 指定消息的角色为用户
                    "role": "user",
                    "content": [
                        # 图片信息，希望模型理解的图片
                        {"type": "image_url", "image_url": {"url":  url}},
                        # 文本消息，希望模型根据图片信息回答的问题
                        {"type": "text", "text": question + "，只告诉我具体坐标数字即可"},
                    ],
                }
            ],
        )
        return completion.choices[0].message.content

